package com.xlh.support.training.controller;

import com.xlh.common.Result;
import com.xlh.security.UserInfoHolder;
import com.xlh.support.training.po.TrainingReportSavePO;
import com.xlh.support.training.service.TrainingReportService;
import com.xlh.support.training.vo.TrainingReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author cheer
 */
@Api("实训报告管理")
@RestController
@RequestMapping("/training/report")
public class TrainingReportController {

    @Autowired
    private UserInfoHolder userInfoHolder;

    @Autowired
    private TrainingReportService trainingReportService;

    @ApiOperation("查询实训实验报告")
    @GetMapping("/{trainingId}")
    public Result<TrainingReportVO> queryTrainingReport(@PathVariable("trainingId") Long trainingId) {
        TrainingReportVO trainingReportVO = trainingReportService.getTrainingReport(userInfoHolder.getUserId(), trainingId);
        return Result.success(trainingReportVO);
    }

    @ApiOperation("保存实训实验报告")
    @PostMapping("/{trainingId}")
    public Result saveTrainingReport(@PathVariable("trainingId") Long trainingId,
                                     @RequestBody TrainingReportSavePO trainingReportSavePO) {
        trainingReportService.saveTrainingReport(userInfoHolder.getUserId(), trainingId, trainingReportSavePO);
        return Result.success();
    }

    @ApiOperation("下载实训实验报告")
    @GetMapping("/{trainingId}/download")
    public Result downloadTrainingReport(@PathVariable("trainingId") Long trainingId) {
        trainingReportService.downloadTrainingReport(userInfoHolder.getUserId(), trainingId);
        return Result.success();
    }
}
